﻿using System;
using System.Windows.Data;
using BizControl.Library.BusinessObjects.Marks;
using BizControl.Library.BusinessObjects.Activities;

namespace BizControl.Presentation.ActivityEditModule.Converters
{
  public class ConditionRequiredValueConverter : IMultiValueConverter
  {
    private readonly int MarkIndex = 0;
    private readonly int ActivityIndex = 1;

    #region IMultiValueConverter Members

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      if (values[MarkIndex] != null)
        return values[MarkIndex];
      if (values[ActivityIndex] != null)
        return values[ActivityIndex];
      return null;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
      object[] result = new object[2];
      if ((value as MarkInfo) != null)
      {
        result[MarkIndex] = value;
        result[ActivityIndex] = null;
      }
      if ((value as ActivityInfo) != null)
      {
        result[MarkIndex] = null;
        result[ActivityIndex] = value;
      }
      return result;
    }

    #endregion
  }
}
